/******************************************
 * mmu.h								  *
 * class structure for InvertedPageTable  *
 * By OceanMaster						  *
 ******************************************/
#include "translate.h"
#include "system.h"

#ifdef USE_TLB

#ifndef MMU_H
#define MMU_H

//----------------------
//	  Generic
//----------------------
extern bool useFIFO;				//the Algorithm used to select memory page to evict
void initMMU();
void finalizeMMU();

//----------------------
//	  Swap File
//----------------------
#define SwapFilePages	1024		//how many pages can be stored in swap file
//OpenFile * SwapFile;
//BitMap * SwapFileMap;
extern void giveupSwap(int posId);
extern void ReadFromSwap(int physicalPage, int posId);

//----------------------
//    TLB Management
//----------------------
extern bool OnMissTLB(unsigned int VAddr);
extern void TLBCleanUp();
//----------------------
//    IPT Management
//----------------------
class InvertedTranslationEntry : public TranslationEntry
{
	public:
		int processId;
};

//extern InvertedTranslationEntry * * ipt;
extern int evictIPT();	//return empty physical page number
extern void populateIPT(int vpn, int physicalPage, bool isValid, bool isUse, bool isDirty, bool readOnly);	//Physical Page should be returned after populate. -1 if failed.
extern InvertedTranslationEntry * queryIPT(int vpn);
extern void recycleIPT(int vpn);						
extern int OnMissIPT(int vpn);
#endif //MMU_H

#endif //USE_TLB
